package com.seaboxdata.jt809.kafka.serializer;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.seaboxdata.jt809.packet.JT809Packet0x1402;
import org.apache.kafka.common.serialization.Deserializer;

import java.io.IOException;
import java.util.Map;

/**
 * @ClassName JT809Packet0x1402Deserializer
 * @Description JT809Packet0x1402反序列化类
 * @Author DFJX
 * @Company 北京东方金信科技有限公司
 * @Date 2020/7/21 9:11
 * Version 1.0
 **/
public class JT809Packet0x1402Deserializer implements Deserializer<JT809Packet0x1402> {
    @Override
    public void configure(Map<String, ?> map, boolean b) {

    }

    @Override
    public JT809Packet0x1402 deserialize(String s, byte[] bytes) {
        ObjectMapper mapper=new ObjectMapper();
        mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        mapper.registerModule(new JavaTimeModule());
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        JT809Packet0x1402 packet0x1402=null;
        try {
            String str=new String(bytes);
            str=str.replace("\\u0000","");
            System.out.println(str);
           packet0x1402= mapper.readValue(bytes,JT809Packet0x1402.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return packet0x1402;
    }

    @Override
    public void close() {

    }
}
